package com.legutech.gsyvideoplayer.gsy_video_player;

import java.util.HashMap;

public class NeedMutesUtil {
    private  static NeedMutesUtil mNeedMutesUtil;
    public   static NeedMutesUtil getInstance(){
        if (mNeedMutesUtil==null){
            synchronized (NeedMutesUtil.class){
                if (mNeedMutesUtil==null)mNeedMutesUtil=new NeedMutesUtil();
            }
        }
        return mNeedMutesUtil;
    }
    private HashMap<String, NeedMutesObserver> observerHashMap = new HashMap<>();

    public void attachObserver(String key, NeedMutesObserver observer) {
        observerHashMap.put(key, observer);
    }

    public void detachObserver(String key) {
        observerHashMap.remove(key);
    }



    public void setAudioState(String key, boolean isAudio){
        if (observerHashMap==null)observerHashMap=new HashMap<>();
        for (NeedMutesObserver observer:observerHashMap.values()){
            observer.changeNeedMutes(true);
        }
        observerHashMap.get(key).changeNeedMutes(!isAudio);
    }


    public void clearAll() {
        observerHashMap.clear();
    }
}
